package top.swimmer.tokenizer.dictionary;

import top.swimmer.tools.io.IOUtils;

import java.util.ArrayList;

public class ArrayListDictionary extends AbstractDictionary {

    private ArrayList<String> list;

    @Override
    public boolean contains(String key) {
        return list.contains(key);
    }

    @Override
    public boolean contains(String key, int start, int length) {
        return list.contains(key.substring(start, start + length));
    }

    @Override
    protected void clear() {
        list = null;
    }

    @Override
    protected void load() {
        list = new ArrayList<>();
        IOUtils.readFromResource("/dictionary/dic.txt", list::add);
    }
}
